package com.lianboke.link.ad.app;

import android.app.Application;
import android.app.Service;
import android.content.Context;
import android.os.Vibrator;
import android.text.TextUtils;

import com.lianboke.link.ad.locationservices.LocationService;
import com.lianboke.link.ad.utils.KLog;
import com.lianboke.link.ad.utils.SharedPreferencesUtil;
import com.umeng.analytics.MobclickAgent;
import com.baidu.mapapi.SDKInitializer;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;


/**
 * 自定义application
 * Created by admin on 2017/9/6.
 */

public class MyApplication extends Application {
    private static Context instance;
    public static String strVpnName;
    public static String strVpnPwd;
    public static String strCity = "未知";//当前城市信息

    public static volatile  boolean isNetworDialogShow = false;//网络类型对话框是否显示

    public LocationService locationService;
    public Vibrator mVibrator;

    //保存packname 与下载地址
    public static ConcurrentHashMap<String,String> appPackNameUrlMap = new ConcurrentHashMap<String,String>();
    //保存下载地址 与 下载位置
    public static ConcurrentHashMap<String,String> appUrlFilePathMap = new ConcurrentHashMap<String,String>();
    //保存下载地址 与 下载id
    public static ConcurrentHashMap<String,Long> appUrlDownIdMap = new ConcurrentHashMap<String,Long>();

    //需要卸载的apppackname
    public static List<String> appUnInstallPackNameDatas = Collections.synchronizedList(new ArrayList<String>());

    //此时是否时自动启动时间
    public static volatile boolean iAutoTimerOrderTime = false;//此时是否时自动启动任务时间

    @Override
    public void onCreate() {
        super.onCreate();
        isNetworDialogShow = false;
        instance = getApplicationContext();
        //初始化日志
        KLog.init(true, "adapp_log");
        //Umeng统计
        MobclickAgent.setScenarioType(instance, MobclickAgent.EScenarioType.E_UM_NORMAL);

        /***
         * 初始化定位sdk，建议在Application中创建
         */
        locationService = new LocationService(getApplicationContext());
        mVibrator =(Vibrator)getApplicationContext().getSystemService(Service.VIBRATOR_SERVICE);
        SDKInitializer.initialize(getApplicationContext());
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
    }

    /**
     * 获取application 级别的context
     * @return
     */
    public static Context getAppContext(){
        return instance;
    }

    /**
     * 获取用户的vpn 信息
     */
    public static void getUserVpnParams(){
        if(TextUtils.isEmpty(strVpnPwd) || TextUtils.isEmpty(strVpnName)){
            strVpnName = SharedPreferencesUtil.getData(getAppContext(),"user_vpn_name","").toString();
            strVpnPwd = SharedPreferencesUtil.getData(getAppContext(),"user_vpn_pwd","").toString();
        }
    }

}
